<?php

namespace App\Http\Requests\DeviceController;

use App\Models\Pool;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class OrderRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'pool_id' => ['required', 'exists:pools,id'],
            'day'     => ['required', 'integer', 'min:30'],
            'number'  => ['required', 'integer', 'min:'.Pool::where('id', $this->input('pool_id'))->value('min')],
            'pay_password' => ['required', 'payPassword']
        ];
    }

    /**
     * @return array
     */
    public function messages()
    {
        return [
            'pool_id.required' => __('挖矿币种ID不能为空'),
            'pool_id.exists' => __('挖矿币种ID不存在'),
            'day.required' => __('挖矿时间不能为空'),
            'day.integer' => __('挖矿时间必须整数'),
            'day.min' => __('挖矿时间最小30天'),
            'number.required' => __('投入算力不能为空'),
            'number.integer' => __('投入算力必须是整数'),
            'number.min' => __('投入算力最小'.Pool::where('id', $this->input('pool_id'))->value('min').'T'),
            'pay_password.required' => __('交易密码不能为空'),
        ];
    }
}
